package org.devbg.academy.corejava.shop.db.daos;

import java.util.Date;
import java.util.List;

import org.devbg.academy.corejava.shop.db.entities.Order;
import org.devbg.academy.corejava.shop.db.utils.HibernateSessionManager;
import org.hibernate.Query;
import org.hibernate.Session;

public class OrderDAO extends BaseDAO {

	@SuppressWarnings("unchecked")
	public OrderDAO(Class clazz) {
		super(Order.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<Order> findByDateRange(Date startDate, Date endDate) {
		HibernateSessionManager.openSession();
		Session hbSession = HibernateSessionManager.getCurrentSession();
		Query findByDateRangeQuery = hbSession.createQuery("from Order o" +
				" where o.OrderDate between :start and :end");
		findByDateRangeQuery.setDate("start", startDate);
		findByDateRangeQuery.setDate("end", endDate);
		List<Order> result = findByDateRangeQuery.list();
		return result;
	}
}
